<?php

//权限节点/侧边栏菜单
namespace app\common\model;


use think\Db;
use think\Model;

class AdminMenu extends Model
{
    public static function getMenu(){
        $where = [];
//        只查询【侧边可访问菜单】
        $where[] = ['type','=',10];

//        获取当前用户的所有菜单权限
        $adminRoleArr = AdminRole::getAdminRoleIdArr();
//        如果不是超级管理员
        if (!in_array(1,$adminRoleArr)){
            $menuIdArr = AdminRole::getMenusIdArr();
            if (!empty($menuIdArr)){
                $where[] = ['id','in',$menuIdArr];
            }else{
                return [];
            }
        }

        $data = self::where($where)->order('sort asc,id desc')->select();
        $data = $data->toArray();
        $data = array2tree($data,'pid','subMenus');
        return $data;
    }

    /**
     * 树表格，默认展开
     * @param $value
     * @param $data
     * @return bool
     */
    public function getOpenAttr($value,$data){
        return true;
    }
}
